<template>
	<view>
		<template>
			<view class=" u-p-r-30 u-p-l-30 u-m-t-20">
				<u-row>
					<u-col span="11" text-align="center">
						<scan></scan>
						<scanner></scanner>
						<sm></sm>
						<honeywell></honeywell>
						<hk></hk>
						<u-search placeholder="输入目的库位111111" :clearabled="true" v-model="keyword"
							border-color="#606266"></u-search>
					</u-col>
					<u-col span="1" text-align="center" @click="scang()">
						<view class="u-m-t-14 weikaishi5">
							<u-icon name="scan" color="#2b85e4" size="45"></u-icon>
						</view>
					</u-col>

				</u-row>
			</view>
		</template>
		<u-card padding="16">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-5 weikaishi4">
								<span>商品名称</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-5 weikaishi4 huanhang">
								<span style="font-size: 20px">{{HxStorageOffShelfResult.goodsName}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-10 weikaishi">
								<span>商品码</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-10 weikaishi">
								<span>{{HxStorageOffShelfResult.goodsPcode69}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-10 weikaishi">
								<span>商品编号</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-10 weikaishi">
								<span>{{HxStorageOffShelfResult.goodsNumber}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-10 weikaishi">
								<span>数量</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-10 weikaishi">
								<span>{{HxStorageOffShelfResult.kcNum}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-5 weikaishi">
								<span>所属仓库</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-5 weikaishi huanhang">
								<span>{{HxStorageOffShelfResult.warehouseName}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-10 weikaishi6">
								<span>生产日期</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-10 weikaishi6">
								<span>{{HxStorageOffShelfResult.detailedDate}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="3" text-align="left">
							<view class="u-m-t-10 weikaishi6">
								<span>下架数量</span>
							</view>
						</u-col>
						<u-col span="9" text-align="right">
							<view class="u-m-t-10 weikaishi6">
								<u-input v-model="xjNum" type="digit" :border="true" placeholder="请输入下架数量" />
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="12" text-align="center">
							<view class="u-line-1 u-m-t-2 weikaishi2 lanse">
								<span style="font-size: 25px">现库位：{{HxStorageOffShelfResult.oldPositionNumber}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="center">
							<view class="u-line-1 u-m-t-2 weikaishi2 yiwancheng">
								<scan></scan>><span
									style="font-size: 25px">目的库位：{{HxStorageOffShelfResult.positionNumber}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<view style="height: 90rpx;">
		</view>
		<view class="wrap"
			style="position: fixed;bottom: 0rpx;width: 100%;background-color: #2979ff;z-index: 999;height: 130rpx;">
			<u-line color="#bababa" />
			<u-row>
				<u-col span="12" text-align="center" @click="put()">
					<view class="u-line-1 u-m-t-10 baise" v-if="HxStorageOffShelfResult.oldPositionNumber === keyword || HxStorageOffShelfResult.warehouseId == 64">
						完成
					</view>
				</u-col>
			</u-row>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	import scan from "@/components/uni-scan/scan.vue"
	import scanner from "@/components/uni-scan/scanner.vue"
	import sm from "@/components/uni-scan/sm.vue"
	import honeywell from "@/components/uni-scan/honeywell.vue"
	import hk from "@/components/uni-scan/hk.vue"
	import radio from "@/components/uni-scan/radio.js"
	export default {
		components: {
			scanner,
			scan,
			sm,
			honeywell,
			hk
		},
		data() {
			return {
				dataList: [],
				did: '',
				xjNum: 0,
				HxStorageOffShelfResult: {},
				keyword: ""
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			this.did = open.id
			this.refresh()
		},
		onShow() {
			let that = this
			uni.$off('scan')
			uni.$on('scan', function(res) {
				console.log('扫码结果：', res.codeStr);
				that.keyword = res.codeStr
				if (res.codeStr == that.HxStorageOffShelfResult.oldPositionNumber) {
					// that.put()
				} else {
					that.$refs.uToast.show({
						title: '请扫描源库位',
						type: 'error'
					});
					radio.play_ding_fail();
				}
			})
			uni.$off('scanner') // 每次进来先 移除全局自定义事件监听器
			uni.$on('scanner', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code
				if (res.code == that.HxStorageOffShelfResult.oldPositionNumber) {
					// that.put()
				} else {
					that.$refs.uToast.show({
						title: '请扫描源库位',
						type: 'error'
					});
					radio.play_ding_fail();
				}

			})
			uni.$off('sm') // 每次进来先 移除全局自定义事件监听器
			uni.$on('sm', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code
				if (res.code == that.HxStorageOffShelfResult.oldPositionNumber) {
					// that.put()
				} else {
					that.$refs.uToast.show({
						title: '请扫描源库位',
						type: 'error'
					});
					radio.play_ding_fail();
				}
			})
			uni.$off('honeywell') // 每次进来先 移除全局自定义事件监听器
			uni.$on('honeywell', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code
				if (res.code == that.HxStorageOffShelfResult.oldPositionNumber) {
					// that.put()
				} else {
					that.$refs.uToast.show({
						title: '请扫描源库位',
						type: 'error'
					});
					radio.play_ding_fail();
				}
			})
			uni.$off('hk') // 每次进来先 移除全局自定义事件监听器
			uni.$on('hk', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code
				if (res.code == that.HxStorageOffShelfResult.oldPositionNumber) {
					// that.put()
				} else {
					that.$refs.uToast.show({
						title: '请扫描源库位',
						type: 'error'
					});
					radio.play_ding_fail();
				}
			})
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			scang() {
				let that = this
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						that.keyword = res.result
						if (res.result == that.HxStorageOffShelfResult.oldPositionNumber) {
							// that.put()
						} else {
							that.$refs.uToast.show({
								title: '请扫描源库位',
								type: 'error'
							});
							radio.play_ding_fail();
						}
					},
				})
			},
			put() {
				/* if (typeof this.HxStorageOffShelfResult.positionNumber == 'undefined' || this.HxStorageOffShelfResult
					.positionNumber == null || this.HxStorageOffShelfResult.positionNumber == "") {
					uni.showToast({
						title: "库位不得为空",
						icon: 'none'
					})
					return
				} */
				if(this.xjNum == ''){
					uni.showToast({
						title: "请先输入下架数量",
						icon: 'none'
					})
					return
				}
				uni.showModal({
					title: '确认下架吗',
					content: '目的库位：' + this.HxStorageOffShelfResult.positionNumber,
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中...'
							})
							this.$http.post('/rest/hxStorageOffShelf/offShelf', {}, {
								params: {
									id: this.did,
									xjNum: this.xjNum,
								},
								header: {
									'Authorization': uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if (res.data.code == 200) {
									this.$refs.uToast.show({
										title: '下架成功',
										type: 'success'
									})
									radio.play_ding_success();
									setTimeout(() => {
										this.$Router.back()
									}, 1000)
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
									radio.play_ding_cuole();
									setTimeout(() => {
										this.refresh()
									}, 1000)
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			refresh() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/hxStorageOffShelf/detail', {}, {
					params: {
						id: this.did
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					if (res.data.success) {
						this.HxStorageOffShelfResult = res.data.data;
						this.xjNum = this.HxStorageOffShelfResult.kcNum;
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.$Router.back()
						}, 1500)
					}
				})
				uni.hideLoading()
			},
		},
	}
</script>
<style lang="scss">
	.huanhang {
		word-break: break-all;
	}

	.jiange {
		border-bottom: 1px solid #e1e1e1;
	}

	.wrap {
		padding: 0rpx 12rpx;
	}

	.baise {
		background-color: #2979ff;
		color: #ffffff;
		font-size: 40rpx;
	}
</style>